package com.struts2.action;

import java.util.ArrayList;
import java.util.List;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import com.struts2.model.Product_line;
import com.struts2.service.AdminService;
import com.struts2.service.ProductListService;

public class AdminProductAction extends ActionSupport implements ModelDriven<List<Product_line>>{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private List<Product_line> product_line;
	
	private String gender ="";
	private String type ="";
	private String category ="";
	private List<String> leftSideMenuList;
	private List<String> leftSideSubMenuList;
	private int productPerPage = 10;
	private int pageNum =1;
	private int maxPage =0;
	

	public String execute() {
		
		AdminService as = new AdminService();
		product_line = as.GetProductList(product_line,productPerPage, pageNum, gender, type, category);
		
		
		double a = Math.ceil((double)as.GetProductCount(product_line, gender, type, category)/productPerPage);
		setMaxPage((int)a);
		
		leftSideMenuList = new ArrayList<String>();
		leftSideMenuList = as.getLeftSideMenu(leftSideMenuList, gender, type, category);
		
		leftSideSubMenuList = new ArrayList<String>();

		if(category!="")
		{
			leftSideSubMenuList = as.getLeftSubSideMenu(leftSideSubMenuList, gender, type, category);
		}
		System.out.println(product_line);
		System.out.println(gender + "  \n" + type +"  \n" + category);
		
		
		return "1";
	}
	
	

	@Override
	public List<Product_line> getModel() {
		// TODO Auto-generated method stub
		return null;
	}

	
	///*************************************************

	public String getGender() {
		return gender;
	}

	public void setGender(String gender) {
		this.gender = gender;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public String getCategory() {
		return category;
	}

	public void setCategory(String category) {
		this.category = category;
	}

	public List<String> getLeftSideMenuList() {
		return leftSideMenuList;
	}

	public void setLeftSideMenuList(List<String> leftSideMenuList) {
		this.leftSideMenuList = leftSideMenuList;
	}

	public List<String> getLeftSideSubMenuList() {
		return leftSideSubMenuList;
	}

	public void setLeftSideSubMenuList(List<String> leftSideSubMenuList) {
		this.leftSideSubMenuList = leftSideSubMenuList;
	}

	public int getProductPerPage() {
		return productPerPage;
	}

	public void setProductPerPage(int productPerPage) {
		this.productPerPage = productPerPage;
	}

	public int getPageNum() {
		return pageNum;
	}

	public void setPageNum(int pageNum) {
		this.pageNum = pageNum;
	}

	public int getMaxPage() {
		return maxPage;
	}

	public void setMaxPage(int maxPage) {
		this.maxPage = maxPage;
	}

	public List<Product_line> getProduct_line() {
		return product_line;
	}

	public void setProduct_line(List<Product_line> product_line) {
		this.product_line = product_line;
	}

	
	// *////////////////////////////////////////////////////////////////
		
	
}
